"""
这是我的面板页面类
"""
from selenium.common import NoSuchElementException

from framwork.pages.base_page import BasePage
# 引入by方法
from selenium.webdriver.common.by import By

class MyPanelPage(BasePage):
    """先写定位器，再写方法"""
    add_zjbtn_locator = (By.ID, "add")  # 添加组件按钮
    zjm_input_locator = (By.CSS_SELECTOR, "#title")  # 组件名输入框
    save_btn_locator = (By.CSS_SELECTOR, "#dialog-message > form > div:nth-child(4) > div > input.btn.btn-primary")
    add_module_seccess_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    # 删除组件按钮
    delete_zj_btn_locator = (By.CSS_SELECTOR,
                             "#widgets > div > div.sort-list.ui-sortable > div:nth-child(1) > div > div.dash-title > small > a.delete_sales")
    delete_module_error_locator = (By.CSS_SELECTOR,"body > div.container > div.alert.alert-error")
    #步骤方法

    def delete_module_error(self):
        try:
            text = self.find_element(self.delete_module_error_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def click_delete_zj(self):
        '''点击删除组件按钮'''
        self.find_element(self.delete_zj_btn_locator).click()

    def click_save(self):
        '''点击保存按钮'''
        self.find_element(self.save_btn_locator).click()

    def click_add_module(self):
        """点击添加组件"""
        self.find_element(self.add_zjbtn_locator).click()

    def input_module_name(self, module_name):
        """输入组件名称"""
        self.find_element(self.zjm_input_locator).send_keys(module_name)

    def add_module_seccess_text(self):
        try:
            text = self.find_element(self.add_module_seccess_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def accept_alert(driver):
        try:
            super().switch_to_alert_accpet()
            return True
        except:
            return False
        # 成功返回 True，失败返回 False
